/**
 * 
 */
package com.tcc.assessment.studentrole.shownavigationmap;

import org.apache.xpath.operations.String;
import org.testng.Assert;
import org.testng.annotations.Test;

import com.tcc.assessment.logic.Playback;
import com.tcc.qa.test.util.BaseTest;
import com.tcc.qa.test.util.SelLogger;

/**
 * @company CampusCruiser
 * @author Emily_Wang
 * @date 2012-8-10
 */
public class BaseTest17to26A extends BaseTest {
  //This string is the Xpath of the page location.

  int errorCount = 0;

  // Initialization Log
  private SelLogger logger = SelLogger.getLogger(getClassObj());

  public String assessmentTitle() {
    return "";
  }

  public Class<?> getClassObj() {
    return null;
  }

  @Test(description = "Goto My Assessment Page and Start Session")
  public void A_setUp() throws InterruptedException {
    Playback.initPlaybacker(getWebDriver(), assessmentTitle());
  }

  @Test(description = "Page1")
  public void B_page1() throws InterruptedException {
    getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    Playback.switchWindow(getWebDriver());
    Assert.assertTrue(Playback.getPageNavInfo(getWebDriver()).contains("Page 1 of 4"), "Page1 >> Pagination info is incorrect!");
    Assert.assertTrue(Playback.getTitleInfo(getWebDriver()).contains(assessmentTitle()), "Page1 >> Page Title is incorrect!");
    Playback.getShortAnswerObj(getWebDriver(), 2).sendKeys("2");
    Playback.getChooseOneAsnwerObj(getWebDriver(), 3, 4).click();
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 1, 3, "White");
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 4, 4, "Grey");
    Playback.goNextPlaybackPage(getWebDriver());
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 1, 1, "Green");
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 2, 3, "White");
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 4, 4, "Grey");
    Playback.goNextPlaybackPage(getWebDriver());
    if(!assessmentTitle().equals("Assessment9")&&!assessmentTitle().equals("Assessment11")){
      Playback.switchWindow(getWebDriver());
      Playback.goNextPlaybackPage(getWebDriver());
    }
    else{
      logger.pass("Only Assessment19 can come here.");
    }
  }

  @Test(description = "Page2, no answer")
  public void C_page2() throws InterruptedException {
    getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    Playback.switchWindow(getWebDriver());
    Assert.assertTrue(Playback.getPageNavInfo(getWebDriver()).contains("Page 2 of 4"), "Page2 >> Pagination info is incorrect!");
    Assert.assertTrue(Playback.getTitleInfo(getWebDriver()).contains(assessmentTitle()), "Page2 >> Page Title is incorrect!");
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 1, 1, "Green");
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 2, 3, "White");
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 4, 4, "Grey");
    Playback.goNextPlaybackPage(getWebDriver());

  }

  @Test(description = "Page3, answer fail")
  public void D_page3() throws InterruptedException {
    getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    Playback.switchWindow(getWebDriver());
    Assert.assertTrue(Playback.getPageNavInfo(getWebDriver()).contains("Page 3 of 4"), "Page3 >> Pagination info is incorrect!");
    Assert.assertTrue(Playback.getTitleInfo(getWebDriver()).contains(assessmentTitle()), "Page3 >> Page Title is incorrect!");
    Playback.getShortAnswerObj(getWebDriver(), 1).sendKeys("6");
    for (int i = 0; i < 5; i++) {
      Playback.getMatchingOneObj(getWebDriver(), 2, i + 1).sendKeys(String.valueOf(i + 1));
    }
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 1, 1, "Green");
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 2, 3, "White");
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 4, 4, "Grey");
    Playback.goNextPlaybackPage(getWebDriver());
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 1, 1, "Green");
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 2, 2, "White");
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 3, 3, "Red");
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 4, 4, "Grey");
    if(!assessmentTitle().equals("Assessment19")){
      Playback.switchWindow(getWebDriver());
      Playback.goNextPlaybackPage(getWebDriver());
    }
    else{
      logger.pass("Only Assessment19 can come here.");
    }
  }
  @Test(description="Page4")
  public void E_page4(){
    Playback.switchWindow(getWebDriver());
    Assert.assertTrue(Playback.getPageNavInfo(getWebDriver()).contains("Page 4 of 4"), "Page4 >> Pagination info is incorrect!");
    Assert.assertTrue(Playback.getTitleInfo(getWebDriver()).contains(assessmentTitle()), "Page4 >> Page Title is incorrect!");
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 1, 1, "Green");
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 2, 2, "White");
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 3, 3, "Red");
    errorCount += Playback.checkNavMapColor(getWebDriver(), logger, 4, 4, "Grey");
  }
  @Test(description = "Finish")
  public void F_finish() throws InterruptedException {
    Playback.finishAndClosePlaybacker(getWebDriver());
  }

  @Test(description = "errorInfo")
  public void G_errorInfo() throws InterruptedException {
    System.out.println("The error count is " + errorCount);
    Assert.assertTrue(errorCount == 0);
  }
}
